package com.tsing.bms.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tsing.bms.dto.NameAndPhoneDto;
import com.tsing.bms.entity.Carport;
import com.tsing.bms.vo.req.CarportPageReqVo;
import com.tsing.bms.vo.resp.CarportRageRespVo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author TheTsing
 * @since 2021-03-29
 */
public interface CarportMapper extends BaseMapper<Carport> {

    @Select("<script>" +
            "select 1 from t_carport c\n" +
            "inner join t_user u on c.id=u.carport_id\n" +
            "where c.id in\n" +
            "<foreach collection='ids' item='item' open='(' close=')' separator=',' >\n" +
            "#{item}\n" +
            "</foreach>\n" +
            "limit 1" +
            "</script>")
    String haveRelevance(@Param("ids") List<String> ids);

    @Select("<script>" +
            "select c.*,d.name depotName,u.nick_name userName,u.phone userPhone\n" +
            "from t_carport c\n" +
            "left join t_depot d on c.depot_id=d.id\n" +
            "left join t_user u on c.id=u.carport_id\n" +
            "<where>\n" +
            "<if test=\"reqVo.username!=null and reqVo.username!=''\">and u.nick_name like concat('%',#{reqVo.username},'%')</if>\n" +
            "<if test=\"reqVo.name!=null and reqVo.name!=''\">and c.name like concat('%',#{reqVo.name},'%')</if>\n" +
            "<if test=\"reqVo.householdId!=null and reqVo.householdId!=''\">and c.household_id=#{reqVo.householdId}</if>\n" +
            "</where>\n" +
            "</script>")
    List<CarportRageRespVo> carportPage(CarportPageReqVo reqVo, Page<Carport> page);

    @Select("select nick_name name,phone from t_user where id=#{id}")
    NameAndPhoneDto selectZhuhu(@Param("id") String householdId);

}
